package com.huawei.deveco.common.security.encrypt;

import com.huawei.deveco.common.security.exception.CryptoException;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

public class CryptoKitFactory {
    private static final Map<String, Supplier<CryptoKit>> CRYPTO_KIT_MAP = new HashMap<>();

    static {
        CRYPTO_KIT_MAP.put("AES-GCM-128", AesGcmKit::new);
    }

    public static CryptoKit getInstance(String kitName) throws CryptoException {
        return ((Supplier<CryptoKit>) Optional.<Supplier>ofNullable(CRYPTO_KIT_MAP.get(kitName))
                .orElseThrow(() -> new CryptoException("Invalid kit name " + kitName)))
                .get();
    }
}
